﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OpenPhotoAlbum.Controls;
using OpenPhotoAlbum.Shared;

namespace OpenPhotoAlbum.My
{
    public partial class My : System.Web.UI.MasterPage
    {
		private DbAccess.User _user;

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			ltrTitle.Text = StringUtility.FormatAndHtmlEncode(
				Resources.Strings.Shared_Title, this.User.UserName);
			//ltrAddress.Text = StringUtility.FormatAndHtmlEncode(
			//    "{0}://{1}{2}",
			//    Request.Url.Scheme,
			//    Request.Url.Host,
			//    UrlContext.BuildSharedHomeUrl(this.User.UserName));
			ltrAddress.Text = string.Empty;
			ltrAddress.Visible = false;
			hlSwitchToSharingMode.Text = Resources.Strings.My_SwitchToSharingMode;
			hlSwitchToSharingMode.NavigateUrl = UrlContext.BuildSharedHomeUrl(this.User.UserName);
		}

		public DbAccess.User User
		{
			get
			{
				if (_user == null)
				{
					string userName = HttpContext.Current.User.Identity.Name;
					if (string.IsNullOrEmpty(userName)) { throw new Exception(); }

					_user = BusinessLogics.UserManager.Instance.GetUser(userName);
					if (_user == null) { throw new UserNotFoundException(); }
				}
				return _user;
			}
		}

		public string BuddyIconImageUrl
		{
			get { return UrlContext.BuildPhotoPipeUserIconUrl(this.User.UserId); }
		}

		public string SettingsPageUrl
		{
			get { return UrlContext.BuildMySettingsUrl(2); }
		}
    }
}
